package com.kaihong.template.ble.operation;

import com.kaihong.template.ble.operation.callback.gatt.BleCharacteristicValueChangeCallback;
import com.kaihong.template.ble.operation.callback.gatt.BleConnectionStateChangeCallback;
import com.kaihong.template.ble.operation.callback.gatt.BleServicesDiscoveredCallback;
import com.kaihong.template.ble.operation.callback.gatt.EnableNotifyIndicateCallback;
import com.kaihong.template.ble.operation.callback.gatt.ReadBleCharacteristicValueCallback;
import com.kaihong.template.ble.operation.callback.gatt.ReadBleDescriptorValueCallback;
import com.kaihong.template.ble.operation.callback.gatt.WriteBleCharacteristicValueCallback;
import com.kaihong.template.ble.operation.callback.gatt.WriteBleDescriptorValueCallback;
import com.kaihong.template.ble.operation.model.DescriptorData;

/**
 * Ble Gatt Processor
 */
public interface BleGattProcessor {
    /**
     * Create a connection with the mobile phone Bluetooth adapter through the specified device UUID
     *
     * @param deviceId Bluetooth device ID
     * @return error code：0, 11001(Internal error/system error), 11002(Failed to connect to BLE Bluetooth device)
     */
    int createBleConnection(String deviceId);

    /**
     * Disconnect the connection with the Bluetooth adapter of the mobile phone through the specified device UUID
     *
     * @param deviceId Bluetooth device ID
     * @return error code：0, 11001(Internal error/system error), 11003(Failed to disconnect BLE Bluetooth device)
     */
    int closeBleConnection(String deviceId);

    /**
     * The device actively reports the change of Bluetooth low energy connection status
     *
     * @param connectionStateChangeCallback Callback for device connection status changes
     */
    void onBleConnectionStateChange(BleConnectionStateChangeCallback connectionStateChangeCallback);

    /**
     * After the Bluetooth device establishes a connection, it starts to discover the services supported by the device,
     * and when the service is discovered, a callback notification
     *
     * @param servicesDiscoveredCallback Discovery service callback
     */
    void onBleServicesDiscovered(BleServicesDiscoveredCallback servicesDiscoveredCallback);

    /**
     * Read the characteristic value of the Bluetooth low energy device and return it as a hexadecimal string
     *
     * @param deviceId Bluetooth device ID
     * @param serviceId The UUID of the service
     * @param characteristicId The UUID of the characteristic value of the Bluetooth device
     * @param readBleCharacteristicValueCallback Callback function for reading the characteristic value
     */
    void readBleCharacteristicValue(String deviceId, String serviceId, String characteristicId,
        ReadBleCharacteristicValueCallback readBleCharacteristicValueCallback);

    /**
     * Write the specified data with the ID of the specified service
     *
     * @param descriptorData descriptorData
     * @param writeCharacteristicCallback Callback of the result of writing the characteristic value
     */
    void writeBleCharacteristicValue(DescriptorData descriptorData,
        WriteBleCharacteristicValueCallback writeCharacteristicCallback);

    /**
     * Set whether the Bluetooth low energy device turns on the mode of characteristic value of the specified service
     *
     * @param deviceId Bluetooth device ID
     * @param serviceId The UUID of the service
     * @param characteristicId The UUID of the characteristic value of the Bluetooth device
     * @param enableNotify Whether to enable notify. true is enable，false is disable
     * @return zero is success, otherwise failed
     */
    int notifyBleCharacteristicValueChange(String deviceId, String serviceId, String characteristicId,
        boolean enableNotify);

    /**
     * Read the descriptor of the Bluetooth low energy device and return it as a hexadecimal string
     *
     * @param deviceId Bluetooth device ID
     * @param serviceId The UUID of the service
     * @param characteristicId The UUID of the characteristic value of the Bluetooth device
     * @param descriptorId The UUID of the Bluetooth device descriptor
     * @param readBleDescriptorValueCallback Callback for reading descriptor
     * @return zero is success, otherwise failed
     */
    int readBleDescriptorValue(String deviceId, String serviceId, String characteristicId, String descriptorId,
        ReadBleDescriptorValueCallback readBleDescriptorValueCallback);

    /**
     * Write the specified data to the descriptor by the ID of the specified service
     *
     * @param descriptorData descriptorData
     * @param writeBleDescriptorValueCallback Callback of write descriptor
     * @return zero is success, otherwise failed
     */
    int writeBleDescriptorValue(DescriptorData descriptorData,
        WriteBleDescriptorValueCallback writeBleDescriptorValueCallback);

    /**
     * The device actively reports the write descriptor result
     *
     * @param enableNotifyIndicateCallback Callback of the result of writing the specified service data
     */
    void onEnableNotifyIndicate(EnableNotifyIndicateCallback enableNotifyIndicateCallback);

    /**
     * The registered device actively reports the change of the characteristic value of the Bluetooth low energy device
     *
     * @param characteristicValueChangeCallback Callback of characteristic value change
     */
    void onBleCharacteristicValueChange(BleCharacteristicValueChangeCallback characteristicValueChangeCallback);

    /**
     * Set low energy Bluetooth working mode
     *
     * @param isEnableIndication true: Enable Indication,false：disable Indication,Enable notification. default is false
     */
    void setEnableIndication(boolean isEnableIndication);
}
